import '../utils/date_utils.dart';
import 'paging_model.dart';
import 'result_model.dart';

///学校班级:查询:请求
class SchoolClassQueryReq extends PagingQueryReq {
  final String schoolId, title;
  final int enterYear, status;

  SchoolClassQueryReq({
    required this.schoolId,
    required this.title,
    required this.enterYear,
    required this.status,
    super.index,
    super.size,
  });

  @override
  Map<String, dynamic> toMap() {
    final map = super.toMap();
    map['title'] = title;
    map['enterYear'] = enterYear;
    map['status'] = status;
    return map;
  }
}

///学校班级:查询:响应
class SchoolClassQueryRes extends PagingQueryRes<SchoolClassItemRes> {
  SchoolClassQueryRes({
    required super.retCode,
    required super.retMessage,
    super.total,
    super.rows,
  });

  factory SchoolClassQueryRes.fromModel(final ResultModelRes res) {
    final ret = PagingQueryRes.fromModel(
      res,
      (row) => SchoolClassItemRes.fromMap(row),
    );
    return SchoolClassQueryRes(
      retCode: ret.retCode,
      retMessage: ret.retMessage,
      total: ret.total,
      rows: ret.rows,
    );
  }
}

///学校班级:数据项:响应
class SchoolClassItemRes {
  final String id, code, title, remark;
  final int enterYear, status;
  final DateTime? createdAt;

  SchoolClassItemRes({
    required this.id,
    required this.code,
    required this.title,
    required this.remark,
    required this.enterYear,
    required this.status,
    this.createdAt,
  });

  factory SchoolClassItemRes.fromMap(final Map<String, dynamic> map) =>
      SchoolClassItemRes(
        id: map['id'] ?? '',
        code: map['code'] ?? '',
        title: map['title'] ?? '',
        remark: map['remark'] ?? '',
        enterYear: map['enterYear'] ?? 0,
        status: map['status'] ?? 0,
        createdAt: dateUtils.parse('yyyy-MM-dd HH:mm:ss', map['createdAt']),
      );
}

///学校班级:加载:响应
class SchoolClassInfoRes extends SchoolClassItemRes with ModelRes {
  @override
  final int retCode;
  @override
  final String retMessage;

  SchoolClassInfoRes({
    required this.retCode,
    required this.retMessage,
    required SchoolClassItemRes item,
  }) : super(
          id: item.id,
          code: item.code,
          title: item.title,
          remark: item.remark,
          enterYear: item.enterYear,
          status: item.status,
          createdAt: item.createdAt,
        );

  factory SchoolClassInfoRes.fromModel(final ResultModelRes res) =>
      SchoolClassInfoRes(
        retCode: res.retCode,
        retMessage: res.retMessage,
        item: SchoolClassItemRes.fromMap(res.toMap),
      );
}

///学校班级:新增:请求
class SchoolClassAddReq {
  final String schoolId, code, title, remark;
  final int enterYear;

  SchoolClassAddReq({
    required this.schoolId,
    required this.code,
    required this.title,
    required this.remark,
    required this.enterYear,
  });

  Map<String, dynamic> toMap() => {
        'code': code,
        'title': title,
        'remark': remark,
        'enterYear': enterYear,
      };
}

////学校班级:修改:请求
class SchoolClassModifyReq {
  final String id, code, title, remark;
  final int enterYear, status;

  SchoolClassModifyReq({
    required this.id,
    required this.code,
    required this.title,
    required this.remark,
    required this.enterYear,
    required this.status,
  });

  Map<String, dynamic> toMap() => {
        'code': code,
        'title': title,
        'remark': remark,
        'enterYear': enterYear,
        'status': status,
      };
}
